package com.zhengqing.app.model.vo;

import com.zhengqing.app.model.enums.ApiResultCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <p> API响应参数 </p>
 *
 * @author zhengqingya
 * @description
 * @date 2024/5/13 16:36
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("API响应参数")
public class ApiResult<T> {

    /**
     * {@link ApiResultCodeEnum}
     */
    @ApiModelProperty("响应码")
    private Integer code;
    @ApiModelProperty("消息内容")
    private String msg;
    @ApiModelProperty("响应数据")
    private T data;

    public static <T> ApiResult<T> ok(T data) {
        return (ApiResult<T>) ApiResult.builder()
                .data(data)
                .code(ApiResultCodeEnum.SUCCESS.getCode())
                .msg("OK")
                .build();
    }

    public static <T> ApiResult<T> fail(String msg) {
        return (ApiResult<T>) ApiResult.builder()
                .data(null)
                .code(ApiResultCodeEnum.FAIL.getCode())
                .msg(msg)
                .build();
    }


}
